package org.eclipseuseradmin.ui.utils;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.forms.editor.FormEditor;

public class EditorSupport {

	private Map<Object, IStatus> pagesValidationStatus = new HashMap<Object, IStatus>();

	private FormEditor editor;

	private boolean dirty = false;

	public EditorSupport(FormEditor editor) {
		this.editor = editor;
	}

	public boolean isError() {
		return !pagesValidationStatus.isEmpty();
	}

	public boolean isDirty() {
		return dirty;
	}

	public void setDirty(boolean dirty) {

		if (this.dirty != dirty) {
			this.dirty = dirty;
			editor.editorDirtyStateChanged();
		}
	}
	
	public void addError(Object key, IStatus status) {
		pagesValidationStatus.put(key, status);
	}
	
	public void removeError(Object key) {
		pagesValidationStatus.remove(key);
	}
}
